//
//  DHAnchordescTableViewCell.m
//  Moment
//
//  Created by dllo on 15/12/29.
//  Copyright © 2015年 片刻. All rights reserved.
//

#import "DHAnchordescTableViewCell.h"

@implementation DHAnchordescTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createViews];
    }
    return self;
}
-(void)createViews{

    _myFlowLayOut = [[UICollectionViewFlowLayout alloc]init];
    _myCollectionView = [[UICollectionView alloc]initWithFrame:[[UIScreen mainScreen] bounds] collectionViewLayout:_myFlowLayOut];
    [self.contentView addSubview:_myCollectionView];
    
    _myCollectionView.delegate = self;
    _myCollectionView.dataSource = self;
    _myCollectionView.backgroundColor = [UIColor whiteColor];
    
    //    [collectionView registerClass:[UICollectionViewCell class] forCellReuseIdentifier:@"collection"];
    [_myCollectionView registerClass:[DHRadioCollectionViewCell class] forCellWithReuseIdentifier:@"DHRadioCollectionViewCell"];
    //    设置每个item的大小
    _myFlowLayOut.itemSize = CGSizeMake((SCREEN_WIDTH  - SCREEN_WIDTH * 0.08 - SCREEN_WIDTH * 0.04)/3 , (SCREEN_WIDTH  - SCREEN_WIDTH * 0.08 - SCREEN_WIDTH * 0.04)/3);
    //    这只最小行间距
    _myFlowLayOut.minimumInteritemSpacing = SCREEN_WIDTH * 0.02;
    //    设置最小列间距
    _myFlowLayOut.minimumLineSpacing = SCREEN_WIDTH * 0.02;
    //    设置item与四周边界的距离 上左下右
    CGFloat height =SCREEN_HEIGHT * 0.48 -  ((SCREEN_WIDTH  - SCREEN_WIDTH * 0.08 - SCREEN_WIDTH * 0.04)/3 * 2 - SCREEN_WIDTH * 0.04 - SCREEN_WIDTH * 0.02);
    _myFlowLayOut.sectionInset = UIEdgeInsetsMake(SCREEN_WIDTH * 0.04, SCREEN_WIDTH *0.04, height, SCREEN_WIDTH * 0.04);
    //    设置滚动方向
    _myCollectionView.bounces = NO;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if (_nowArr.count < 6||_nowArr.count == 6) {
        return _nowArr.count;
    }else{
    return 6;
    }
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *indetifier = @"DHRadioCollectionViewCell";
    DHRadioCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:indetifier forIndexPath:indexPath];
    cell.moreting =_nowArr[indexPath.item];
    return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    Moreting *moreting = _nowArr[indexPath.item];
    moreting.figure = indexPath.item;
    [[NSNotificationCenter defaultCenter] postNotificationName:@"changRadio" object:
         moreting];
    NSNumber *num  = [NSNumber numberWithInteger:indexPath.item];

    NSDictionary *dic = @{@"Array":_nowArr,@"mark":num};
    [[NSNotificationCenter defaultCenter]postNotificationName:@"sendRadioArray" object:dic];
}
-(void)setNowArr:(NSMutableArray *)nowArr{
    if (_nowArr != nowArr) {
        _nowArr = nowArr;
    }
    [_myCollectionView reloadData];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
